package com.shujia.day19;

/*
    线程组：将属于同一类的线程划分到同一组中，可以直接对线程组进行设置。

    ThreadGroup
        构造方法：
            ThreadGroup(String name) 构造一个新的线程组。

 */
class MyThread1 extends Thread{
    public MyThread1() {
    }

    public MyThread1(ThreadGroup group, String name) {
        super(group, name);
    }

    @Override
    public void run() {
        System.out.println("这是帅哥线程");
    }
}

public class ThreadGroupDemo1 {
    public static void main(String[] args) {
        //创建一个线程组，组名叫做帅哥组
        ThreadGroup tg1 = new ThreadGroup("帅哥组");
        ThreadGroup tg2 = new ThreadGroup("美女组");


        //创建两个线程对象，分配到线程组中
//        MyThread1 t1 = new MyThread1();
//        t1.setName("李刚");
        //Thread(ThreadGroup group, String name)
        //分配一个新的 Thread对象。
        MyThread1 t1 = new MyThread1(tg1, "李刚");
        MyThread1 t2 = new MyThread1(tg1, "钱志强");
        MyThread1 t3 = new MyThread1(tg2, "李世博");
        MyThread1 t4 = new MyThread1(tg2, "杨珊珊");

        System.out.println(t1.getName()+"属于 "+t1.getThreadGroup().getName());
        System.out.println(t2.getName()+"属于 "+t2.getThreadGroup().getName());
        System.out.println(t3.getName()+"属于 "+t3.getThreadGroup().getName());
        System.out.println(t4.getName()+"属于 "+t4.getThreadGroup().getName());


//        t1.setDaemon(true);
//        t2.setDaemon(true);
        tg1.setDaemon(true);

    }
}
